package com.es.designmode.flyweight;

/**
 * 享元模式
 * 运用共享技术有效地支持大量细粒度地对象
 * <p>
 * 可以避免大量非常相似类的开销
 * 如果能把那些参数移到类的实例的外面，在方法调用时将他们传递进来，就可以通过共享大幅度减少单个实例的开销
 * <p>
 * C#的 String 就是享元模式，如果字符串相同，就是相同的实例
 *
 * @author Will
 */
public class ClientSide {

    public static void main(String[] args) {

        int extrinsicstate = 22;

        FlyweightFactory f = new FlyweightFactory();

        Flyweight fx = f.getFlyweight("X");
        fx.operation(--extrinsicstate);

        Flyweight fy = f.getFlyweight("Y");
        fy.operation(--extrinsicstate);

        Flyweight fz = f.getFlyweight("Z");
        fz.operation(--extrinsicstate);

        Flyweight uf = new UnSharedConcreteFlyweight();

        uf.operation(--extrinsicstate);
    }
}
